package StreamStudy;

import java.sql.Array;
import java.util.*;
import java.util.stream.Stream;

public class t1 {
    public static void main(String[] args) {
        Integer[] array = {1,2,3,4};
        Stream<Integer> stream = Arrays.stream(array);
        stream.forEach(item-> System.out.println(item));

//        hashMapEntrySet();
//        hashMapStream();
//        ArraylistStream();

//        extracted();
    }

    private static void hashMapEntrySet() {
        HashMap<String,Integer> hs = new HashMap<>();
        hs.put("张无忌",1);
        hs.put("张良",2);
        hs.put("王二麻子",3);
        hs.put("谢广坤",4);
        hs.put("张三丰",5);
        hs.put("张翠山",1);
        hs.entrySet().stream().forEach(item-> System.out.println(item.getKey()));
        hs.entrySet().stream().forEach(item-> System.out.println(item.getValue()));
        hs.keySet().stream().forEach(item-> System.out.println(item));
        hs.values().stream().forEach(item-> System.out.println(item));
    }

    private static void hashMapStream() {
        HashSet<String> hs = new HashSet<>();
        hs.add("张无忌");
        hs.add("张良");
        hs.add("王二麻子");
        hs.add("谢广坤");
        hs.add("张三丰");
        hs.add("张翠山");
        hs.stream().forEach(item-> System.out.println(item));
    }

    private static void ArraylistStream() {
        List<String> l  = new ArrayList<>();
        l.add("张无忌");
        l.add("张良");
        l.add("王二麻子");
        l.add("谢广坤");
        l.add("张三丰");
        l.add("张翠山");
        l.stream().filter(item->item.startsWith("张")).filter(item->item.length() == 3).forEach(item-> System.out.println(item));
    }

    private static void extracted() {
        List<String> l  = new ArrayList<>();
        l.add("张无忌");
        l.add("张良");
        l.add("王二麻子");
        l.add("谢广坤");
        l.add("张三丰");
        l.add("张翠山");
        List<String> lCopy = new ArrayList<>();
        List<String> lCopy2 = new ArrayList<>();
        l.forEach(item->{
            if(item.startsWith("张")){
                lCopy.add(item);
            }
            if(item.startsWith("张") && item.length() == 3){
                lCopy2.add(item);
            }
        });
        System.out.println(lCopy);
        System.out.println(lCopy2);
    }
}
